<template>
	<zy-search :fixedHead="fixed" v-model="value" :preIconfont="leftIcon"
		:placeholder="$t('public.pleaseInput')+placeholder" clearable :sufBtn="$t('public.search')"
		@preHandler="scanHandle" @sufHandler="searchHandle">
	</zy-search>
</template>

<script>
	export default {
		emits: ['scanHandle', 'searchHandle'],
		props: {
			//默认在头部固定
			fixed: {
				type: Boolean,
				default: true
			},
			placeholder: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				leftIcon: 'iconfont icon-saoyisao', //搜索框左侧图标
				value: '',
			}
		},
		methods: {
			// 左侧扫一扫图标事件
			scanHandle() {
				var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_result) {
							let obj = ret.resp_result.replace(/\s/g, "")
							if (this.$parent.$parent) {
								this.$parent.$parent.searchList(obj);
							} else {
								this.$parent.searchList(obj);
							}
						} else {
							uni.showToast({
								title: this.$t('topSearch.scanTip'),
								icon: "none",
								duration: 3000
							})
						}
					})
			},
			//右侧“查询”按钮事件
			searchHandle() {
				if (this.$parent.$parent) {
					this.$parent.$parent.searchList(this.value);
				} else {
					this.$parent.searchList(this.value);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>